define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'task/lists/index' + location.search,
                    add_url: 'task/lists/add',
                    edit_url: 'task/lists/edit',
                    del_url: 'task/lists/del',
                    multi_url: 'task/lists/multi',
                    import_url: 'task/lists/import',
                    table: 'task_lists',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'type',
                            title: __('Type'),
                            searchList: {"1": __('引导任务'), "2": "系统任务", "3": "自定义任务"},
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'location',
                            title: __('Location'),
                            searchList: {"invite": "邀请注册", "topup": "充值", "game": "对局"},
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'standard_limit', title: __('Standard_limit')},
                        {
                            field: 'award_type', title: __('Award_type'),
                            searchList: {1: "银币", 2: "金币", 3: "积分", 4: "钻石"},
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'amount', title: __('Amount'), operate: 'BETWEEN'},
                        {
                            field: 'date_limit', title: __('Date_limit'),
                            searchList: {"today": "日", "week": "周", "month": "月", "more": "不限制"},
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'frequency_limit', title: __('Frequency_limit')},
                        {
                            field: 'switch',
                            title: __('Switch'),
                            searchList: {"1": __('Yes'), "0": __('No')},
                            table: table,
                            formatter: Table.api.formatter.toggle
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
